package com.example.crawler.youtube.extractor;

import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

/**
 * 从网站https://www.vidpaw.com/downloader/获取视频地址
 * @author Administrator
 */
@Component
public class Y2MateExtractor extends ThirdPlatformExtractor {

    @PostConstruct
    public void init() {
        addIgnoreParam("title");
    }

    @Override
    protected String getRequestUrl(String youtubeVideoUrl) {
        return "https://www.y2mate.info/downl0ader/";
    }

    @Override
    protected Map<String, String> getRequestParameterMap(String youtubeVideoUrl) {
        String videoId = getVideoId(youtubeVideoUrl);
        Map<String, String> param = new HashMap<>(3);
        param.put("url", videoId);
        return param;
    }

    @Override
    protected Map<String, String> getHeaderFields(String youtubeVideoUrl) {
        String videoId = getVideoId(youtubeVideoUrl);
        Map<String, String> param = new HashMap<>(3);
        param.put("referer", String.format("https://www.y2mate.info/downloads/%s/", videoId));
        return param;
    }

    @Override
    public String name() {
        return "y2mate";
    }

    @Override
    public int getOrder() {
        return 20;
    }
}
